export default option => {
  let {
    unAuth,
    mounted,
  } = option;
  function Mounted () {
    if (this.$route.fullPath === '/login' || this.$route.fullPath === '/') {
      if (mounted) mounted.call(this);
      return;
    }
    if (!this.$store.state.USER.authUser) {
      this.postL('/users/login')
        .then(data => {
          this.$store.commit('USER/SET', data);
          if (mounted) mounted.call(this);
        })
        .catch(err => {
          this.$router.replace('/login');
          console.log(err);
        });
    } else {
      if (mounted) mounted.call(this);
    }
  }
  if (!unAuth) {
    option.mounted = Mounted;
  }
};
